public class Sqlist {
	
	public Integer[] list = null;
	public int len; // 顺序表容量
	public int current; // 标记顺序表末尾元素位置
	
	public Sqlist() {
		this(20);
	}
	
	public Sqlist(int length) {
		if (length>=0) {
			this.len = length;
			this.list = new Integer[this.len];
			this.current = -1;
		} else {
			throw new RuntimeException("初始化大小不能小于0");
		}
	}
	
	public boolean insert(int el, int index) {
		if (this.current >= this.len) {
			throw new RuntimeException("顺序表已满");
		} else {
			if (this.current+1 < index || index < 0) {
				throw new RuntimeException("索引无效");
			} else {
				if (index == this.current+1) {
					this.list[++this.current] = el;
					return true;
				} else {
					for (int i = this.current; i > index; i-- ) {
						this.list[i+1] = this.list[i];
					}
					this.current++;
					return true;
				}
			}
		}
	}
	
	public boolean append(int el) {
		if (this.current >= this.len) {
			throw new RuntimeException("顺序表已满");
		} else {
			this.list[++this.current] = el;
			return true;
		}
	}
	
	public boolean delete(int index) {
		if (this.current < index || index < 0) {
			throw new RuntimeException("索引无效");
		} else {
			for (int i = index; i < this.current+1; i++) {
				this.list[i] = this.list[i+1];
			}
			this.list[this.current] = null;
			--this.current;
			return true;
		}
	}
	
	public int get(int index) {
		if (this.current < index || index < 0) {
			throw new RuntimeException("索引无效");
		} else {
			return this.list[index];
		}
	}
	
	public boolean clear() {
		this.current = -1;
		return true;
	}
	
	public int size() {
		return ++this.current;
	}
	
	public int len() {
		return this.len;
	}

	public static void main(String[] args) {
		Sqlist Tlist = new Sqlist();
		for (int i = 0; i < 10; i++) {
			Tlist.append(i);
		}
		Tlist.delete(3);
		// Tlist.clear();
		System.out.println(Tlist.get(8));
		int len = Tlist.size();
		for (int i = 0; i < len; i++) {
			System.out.printf("顺序表元素：%d\n", Tlist.list[i]);
		}
	}

}
